package Test_1;

//单链表的逆置

public class ReturnList {
    public static SingleLinkedList.ListNode reverseList(SingleLinkedList.ListNode head) {
        if(head == null) {
            return null;
        }
        if(head.next == null) {
            return head;
        }
        SingleLinkedList.ListNode cur = head.next;
        head.next = null;
        while(cur != null) {
            SingleLinkedList.ListNode curNext = cur.next;
            cur.next = head;
            head = cur;
            cur = curNext;
        }
        return head;
    }

    public static void main(String[] args) {
        SingleLinkedList s = new SingleLinkedList();
        s.addLast(1);
        s.addLast(2);
        s.addLast(3);
        s.addLast(4);
        ReturnList.reverseList(s.head);
        s.display();
    }
}
